package com.xianrenit.xianrenpuzi.common.log.service.impl;

import com.xianrenit.xianrenpuzi.common.log.mapper.SysOperLogMapper;
import com.xianrenit.xianrenpuzi.common.log.service.SysOperLogService;
import com.xianrenit.xianrenpuzi.model.entity.sys.SysOperLog;
import jakarta.annotation.Resource;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class SysOperLogServiceImpl implements SysOperLogService {
    @Resource
    SysOperLogMapper sysOperLogMapper;
    @Override
    public void save(SysOperLog sysOperLog) {
        //模拟：业务代码执行时间较长
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        sysOperLogMapper.save(sysOperLog);
    }
    //spring-context：@EnableAsync 启用异步任务+  @Async 标注的方法会异步执行
    @Async //表示异步执行
    @Override
    public void asyncSave(SysOperLog sysOperLog) {
        //模拟：业务代码执行时间较长
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        sysOperLogMapper.save(sysOperLog);
    }
}
